package com.gitee.cirnochat.chatai.model.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.gitee.cirnochat.chatai.model.vo.req.aisession.AISessionCreateDTO;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 
 * @TableName ai_chat_session
 */
@TableName(value ="ai_chat_session")
@Data
@NoArgsConstructor
public class AiChatSession implements Serializable {
    /**
     * 主键ID
     */
    @TableId(value = "id")
    private Long id;

    /**
     * 会话名称
     */
    @TableField(value = "session_name")
    private String sessionName;

    /**
     * 用户ID
     */
    @TableField(value = "user_id")
    private Long userId;

    /**
     * 创建时间
     */
    @TableField(value = "create_time")
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField(value = "update_time")
    private LocalDateTime updateTime;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    public AiChatSession(AISessionCreateDTO sessionCreateDTO, Long userId , boolean isNew) {
        BeanUtils.copyProperties(sessionCreateDTO, this);
        this.userId = userId;
        if (isNew) {
            this.id = IdWorker.getId();
            this.createTime = LocalDateTime.now();
            this.updateTime = this.createTime;
        }
    }
}